<template>
  <div class="app-container">
    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
              :max-height="tableMaxHeight">
      <el-table-column label="开票金额" align="center" prop="invoiceMoney"/>
      <el-table-column label="开票日期" align="center" prop="invoiceDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.invoiceDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发票代码" align="center" prop="preNo"/>
      <el-table-column label="发票编号" align="center" prop="taxNo"/>
      <el-table-column align="center" label="发票截图" prop="image" width="200">
        <template slot-scope="scope">
          <image-preview :src="scope.row.image" height="60px" width="40px"></image-preview>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                       v-hasPermi="['develop:GoodsInvoiceInfo:remove']">删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {deleteAction, getAction} from '@/api/manage'
import GoodsInvoiceInfoForm from '@/views/develop/goodsInvoiceInfo/module/GoodsInvoiceInfoForm'

export default {
  name: "GoodsInvoiceInfoListInForm",
  components: {
    GoodsInvoiceInfoForm,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 开票明细信息表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        invoiceMoney: null,
        invoiceDate: null,
        infomation: null,
        projectId: null,
        mainId: null,
        projectName: null,
        preNo: null,
        taxNo: null,
        status: null,
        backMoney: null,
        remainMoney: null
      },
      url: {
        list: '/goodsInvoiceInfo/goodsInvoiceInfo/list',
        remove: '/goodsInvoiceInfo/goodsInvoiceInfo/',
        export: '/goodsInvoiceInfo/goodsInvoiceInfo/export',
      },
      tableMaxHeight: window.innerHeight - 320,
    };
  },
  props: {
    mainId: {
      type: String,
      required: true,
      default: ''
    }
  },
  watch: {
    'mainId': {
      handler(newVal, oldVal) {
        if (newVal) {
          this.queryParams.mainId = newVal;
          this.getList();
        }
      },
      deep: true,
      immediate: true
    }
  },
  created() {
  },
  destroyed() {
  },
  methods: {
    /** 查询开票明细信息列表 */
    getList() {
      this.loading = true;
      getAction(this.url.list, this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getTableHeight() {
      this.tableHeight = window.innerHeight - 320
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.form.handleAdd();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      deleteAction(this.url.remove, ids).then(response => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
        this.$emit('delete');
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(this.url.export, {
        ...this.queryParams
      }, `goodsInvoiceInfo_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
